﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.Filters;
using Common;

namespace FilterModel
{
    /// <summary>
    /// 全局异常过滤器
    /// </summary>
    public class GlobalExceptionFilter : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            Exception ex = actionExecutedContext.Exception;

            #region 记录异常

            Type exceptionType = typeof(Exception);
            if (ex.GetType() == exceptionType)//异常可能被Throw new Exception(e.Message);处理过
            {
                LogHelper.Error("异常可能被程序捕获处理(*^__^*)："+ex.Message);
            }
            else
            {
                LogHelper.Error("异常未被程序捕获处理(●￣(ｴ)￣●)："+ex.Message);
            }

            #endregion

            base.OnException(actionExecutedContext);
        }
    }
}
